﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoTest
{
    public class AutoMapperProfileRegister
    {
        public static void Register()
        {

        }
    }

    class Program
    {
        static void Main(string[] args)
        {

            Address address = new Address()
            {
                A = 0,
                B = "aaa",
                C = true,
                D = "123",
                E = DateTime.Now
            };

            List<Address> ads = new List<Address>();
            for (int i = 0; i < 10; i++)
            {
                ads.Add(new Address()
                {

                    A = i,
                    B = "A" + i
                });
            }




            Mapper.Initialize(cfg =>
            {
                //cfg.CreateMap<Address, AddressDto>().ConstructUsing(s => new AddressDto()
                //{
                //    A1 = s.A,
                //    B1 = s.B,
                //    D1 = s.F.ToString()
                //});
                cfg.CreateMap<Address, AddressDto>().ConstructUsing(s=>new AddressDto()
                {
                    //A1 = s.A,
                    B1 = s.B
                });
            });


            var ms= Mapper.Map<List<AddressDto>>(ads);

            //var config = new MapperConfiguration(cfg => cfg.CreateMap<Address, AddressDto>().ConstructUsing(s => new AddressDto()
            //{

            //    A1 = s.A,
            //    B1 = s.B,
            //    D1 = s.F.ToString()

            //}));

            //var mapper = config.CreateMapper();


            //AddressDto model = Mapper.Map<AddressDto>(address);





        }
    }





    //public static class Mapping
    //{
    //    /// <summary>
    //    /// 注册映射关系 
    //    /// </summary>
    //    public static void Register()
    //    {
    //        Mapper.CreateMap<Student, StudentDto>()
    //            .ForMember(dest => dest.ClassName, mo => mo.MapFrom(src => src.Class.Name))
    //            .ForMember(dest => dest.GradeId, mo => mo.MapFrom(src => src.Class.GradeId))
    //            .ForMember(dest => dest.GradeName, mo => mo.MapFrom(src => src.Class.Grade.Name));
    //        Mapper.CreateMap<StudentDto, Student>()
    //            .ForMember(dest => dest.Gender, mo => mo.Ignore())
    //            .ForMember(dest => dest.Class, mo => mo.Ignore());
    //    }

    //    /// <summary>
    //    /// 领域模型转化为Dto
    //    /// </summary>
    //    /// <param name="entity"></param>
    //    /// <returns></returns>
    //    public static StudentDto ToModel(this Student entity)
    //    {
    //        return Mapper.Map<Student, StudentDto>(entity);
    //    }

    //    /// <summary>
    //    /// Dto转化为领域模型
    //    /// </summary>
    //    /// <param name="model"></param>
    //    /// <returns></returns>
    //    public static Student ToEntity(this StudentDto model)
    //    {
    //        return Mapper.Map<StudentDto, Student>(model);
    //    }

    //    /// <summary>
    //    /// 重载 ToEntity, 在已有 Dto模型基础上使用领域模型转换成 Dto
    //    /// </summary>
    //    /// <param name="model"></param>
    //    /// <param name="entity"></param>
    //    /// <returns></returns>
    //    public static Student ToEntity(this StudentDto model, Student entity)
    //    {
    //        return Mapper.Map(model, entity);
    //    }
    //}
}
